package com.weiyi.mashangzhu.Roomer.Activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Adapter.ListviewAdapter;
import com.weiyi.mashangzhu.Roomer.Bean.MsgInfo;
import com.weiyi.mashangzhu.Utils.UiUtil;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MessageDetailsActivity extends AppCompatActivity {
    private ListviewAdapter adapter = null;

    private ListView listview;
    private EditText et_meg;
    private Button btn_right;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_details);
        ButterKnife.bind(this);
        initView();

        adapter = new ListviewAdapter(this);
        listview.setAdapter(adapter);
        adapter.addDataToAdapter(new MsgInfo("您好，请问有什么可以帮助您的吗？", null));
        adapter.addDataToAdapter(new MsgInfo(null, "您好，我想问一下，您这有什么合适的便宜的房型吗？"));
        adapter.notifyDataSetChanged();
    }

    public void initView() {
        listview = (ListView) findViewById(R.id.listview);
        et_meg = (EditText) findViewById(R.id.et_meg);
        btn_right = (Button) findViewById(R.id.btn_right);


    }

    @OnClick({R.id.back, R.id.person, R.id.btn_right})
    public void onViewClicked(View view) {
        String msg = et_meg.getText().toString().trim();
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.person:
                UiUtil.startActivity(this,LandlordInfoActivity.class);
                break;
            case R.id.btn_right:
                adapter.addDataToAdapter(new MsgInfo(null, msg));
                adapter.notifyDataSetChanged();
                listview.smoothScrollToPosition(listview.getCount() - 1);
                et_meg.setText("");
                break;
        }
    }
}
